/**
 * Some tests of the Graph
 */
GraphAppTest = {

	onLoad: function () {
    console.log("test");
		var graph = new GraphApp.Graph();
		var a = graph.addNode(5, 0, 0);
		console.log(a.id);
		var b = graph.addNode(10, 0, 50);
		
		graph.addEdge(a.id, b.id);
		
		var c = graph.addNode(7, 50, 0);
		graph.addEdge(c.id, a.id);
		graph.addEdge(b.id, c.id);
		graph.addEdge(c.id, b.id);
		
		for (var key in graph.nodes) {
			var node = graph.nodes[key]
			console.log("Node: " + node.value);
			console.log("Edges: ")
			var neighbors = graph.neighbors(node.id)
			for (var nkey in neighbors) {
				console.log(neighbors[nkey]);
			}
		}
		
		graph.removeNode(b.id);
		
		graph.setCoordinates(a.id, 100, 100);

		for (var key in graph.nodes) {
			var node = graph.nodes[key]
			console.log("Node: " + node.value);
			console.log("Edges: ")
			var neighbors = graph.neighbors(node.id)
			for (var nkey in neighbors) {
				console.log(neighbors[nkey]);
			}
		}
		
		var graphb = new GraphApp.Graph();
		var ba = graphb.addNode("test", 0, 0); 
		var bb = graphb.addNode("funzt", 50, 0);
		var bc = graphb.addNode("ok", 0, 50);
		var bd = graphb.addNode("k", 100, 100);
		var be = graphb.addNode("kfj", 200, 200);
		var bf = graphb.addNode("kdfk", 250, 250);
		var bg = graphb.addNode("findme", 40, 30);
		var bh = graphb.addNode("notme", 304, 20);
		
		graphb.addEdge(ba.id, bb.id);
		graphb.addEdge(ba.id, bc.id);
		graphb.addEdge(bb.id, bd.id);
		graphb.addEdge(bb.id, be.id);
		graphb.addEdge(bc.id, bf.id);
		graphb.addEdge(bc.id, bg.id);
		graphb.addEdge(be.id, bh.id);		
		
		// built in cycle
		graphb.addEdge(bh.id, ba.id);
		graphb.addEdge(bh.id, bc.id);
		
		// test bfs
    //var queue = new GraphAppQueue();
    //queue.push("works");
    //console.log(queue.pop());
    var nextgraph = new GraphApp.Graph();

		var bfs = new GraphApp.Traverse.Traverser(graphb);
		bfs.setAlgorithm("DFS");
    bfs.setStartingPoint(ba);
		bfs.setSearchValue("findme");
		
//		var running = true;
//		while (running) {
//			var retval = bfs.step()
//			console.log(retval);
//			if (retval === true || retval === false) {
//				running = false;
//			}
//		}
    
    var steps = bfs.traverse();
    console.log(steps);
    
//    var test = GraphApp.IO.read(fileName)
//    for (var key in test.nodes) {
//      console.log(test.nodes[key]);
//    }
    
	}
};

window.addEventListener("load", function () { GraphAppTest.onLoad(); }, false);